<script src="__PUBLIC__/ganged/Js/city-picker.data.js"></script>
<script src="__PUBLIC__/ganged/Js/city-picker.js"></script>
<script src="__PUBLIC__/ganged/Js/main.js"></script>
<!-- css -->
<link href="__PUBLIC__/ganged/Css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/ganged/Css/city-picker.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" charset="utf-8" src="__PUBLIC__/admin/js/uploadify/jquery.uploadify.min.js" ></script>
<link rel="stylesheet" charset="utf-8" type="text/css" href="__PUBLIC__/admin/js/uploadify/uploadify.css"> 
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/admin/js/upload.js" ></script>
<!-- 定位 -->
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=yWnFso0oyjmX79HzCx1DRz2sBtvweQfI"></script>
<style>
.bg{ background: none; border: none;}
.uploadify-button-text{ display: inline-flex; }
.uploadify-button-text button{ margin: -10px; }
.upviewer img{ height:90px; width: 120px; }
.upviewer ul{ margin:0px; padding:0px; }
.upviewer li{ margin:0px; padding:0px; position: relative; display:inline-block; width:120px; height:90px; background-position: center; background-size: contain; background-repeat: no-repeat; float: left; margin-right:10px; border:1px #ccc solid; background-color:#f0f0f0;}
.upviewer li a{ display:inline-block; position: absolute; bottom:0px; left:0px; text-align:center; width:100%; background-color:rgba(0,0,0,0.3); color:red; cursor: pointer; }
.upviewer li:hover a{ background-color:rgba(0,0,0,0.8); }
</style>
<div class="container" style="padding-top: 50px;">
	<div class="row clearfix">
		<div class="col-md-12 column">
			<form class="form-horizontal" role="form" id="post_form" action="{:U('apply_edit')}">
				<div class="form-group">
					<label for="category" class="col-sm-2 control-label">分类:</label>
					<div class="col-sm-2">
						<div class="control-group">
							<select name="category_id" id="category" class="form-control"> 
								<option value="0">请选择分类</option>
								<volist name="category" id="vo">
									<option value="{$key}" <if condition="$info['category_id'] eq $key">selected</if>>{$vo}</option>
								</volist>
							</select>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label for="title" class="col-sm-2 control-label">维修工姓名:<span style="color: red;">*</span></label>
					<div class="col-sm-5">
						<input type="text" class="form-control" name="name" id="name" value="{$info.name}"/>
					</div>
				</div>
				<div class="form-group">
					 <label for="inputPassword3" class="col-sm-2 control-label">图片(640x360):<span style="color: red;">*</span></label>
					<div class="col-sm-10">
						<input type="file" class="form-control" id="img" name="img" ><br /> 
				    	<div id="view_list" name="img" class="upviewer">
                            <notempty name="info['img']">
                                <li><img src="{$info.img}"/><a d_path="{$info.img}">删除</a></li>
                            </notempty>
                        </div>
					</div>
				</div>
				<div class="form-group">
					 <label for="title" class="col-sm-2 control-label">联系电话:<span style="color: red;">*</span></label>
					<div class="col-sm-5">
						<input type="text" class="form-control" name="mobile" id="mobile" value="{$info.mobile}"/>
					</div>
				</div>
				<div class="form-group">
					<label for="ds" class="col-sm-2 control-label">身份证号:</label>
					<div class="col-sm-5" >
                        <input type="text" class="form-control" name="id_card" id="id_card" value="{$info.id_card}"/>
					</div>
				</div>
                <div class="form-group">
                    <label for="assessment" class="col-sm-2 control-label">自我评价:</label>
                    <div class="col-sm-5" >
                    <textarea class="form-control" name="assessment" id="assessment" rows="5">{$info.assessment}</textarea>
                    </div>
                </div>
				
				
				<!-- 省市三级联动 -->
					<div class="form-group">
					<label for="ds" class="col-sm-2 control-label">省市区:<span style="color: red;">*</span></label>
					<div id="distpicker" style="margin-left:20%">
						<div class="form-group">
							<div style="position: relative;">
								<input id="city-picker3" class="form-control" readonly type="text" value="{$info.province}/{$info.city}/{$info.district}" data-toggle="city-picker" style="width:400px;">
							</div>
						</div>
						<div class="form-group">
							<button class="btn btn-warning" id="reset" type="button">重置</button>
							<button class="btn btn-danger" id="destroy" type="button">确定</button>
						</div>
					</div>
					</div>
				<!-- 三级联动结束 -->

				<div class="form-group">
					<label for="address" class="col-sm-2 control-label">详细地址:<span style="color: red;">*</span></label>
					<div class="col-sm-5">
						<input type="text" class="form-control" name="address" id="address" value="{$info.address}"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">状态:</label>
					<div class="col-sm-10">
						<label for="is_check_status1" class="control-label">
							<input type="radio" id="is_check_status1" name="check_status" value="0" <if condition="$info['check_status'] eq 0">checked</if>>申请中
						</label>
						<label for="is_check_status2" class="control-label">
							<input type="radio" id="is_check_status2" name="check_status" value="1"  <if condition="$info['check_status'] eq 1">checked</if>>同意
						</label>
						<label for="is_check_status3" class="control-label">
							<input type="radio" id="is_check_status3" name="check_status" value="2"  <if condition="$info['check_status'] eq 2">checked</if>>拒绝
						</label>
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-offset-2 col-sm-10">
                        <input type="hidden" name="id" value="{$info.id}">
						<button type="button" class="btn btn-primary" id="btn" lng="0" lat="0">提交</button>
					</div>
				</div>
			</form>
		</div>
</div>
<script>
function getPlace(addr, callback) {
    var myGeo = new BMap.Geocoder();
    var lng = 0;
    var lat = 0;
    myGeo.getPoint(addr, function(point) {
        if(point) {
            lng = point.lng;
            lat = point.lat;
        }
        callback({'lat':lat, 'lng':lng})
    });
}	
$(function(){	
			
    initDelFile();
    //多文件上传
    initUploadify({ ID:'img',url:"{:U('Upload/upload')}",success:function(obj){ 
            if(obj.s){
                $('#view_list').append('<li><img src="'+obj.d+'"/><a d_path="'+obj.d+'">删除</a></li>');
                initDelFile();
            }else{
                alert(obj.m);
            }
        } 
    });

    function initDelFile(){
        $('.upviewer li a').unbind('click').click(function(){
            if(!confirm('你确认删除吗?')) return false;
            var _this = $(this);
            var dpath = $(_this).attr('d_path');
            if(!dpath) return false;
            $.post("{:U('Upload/delfile')}",{filepath:dpath},function(obj){ 
                if(obj.s){ 
                    $(_this).parents('li').remove();
                }else{
                    alert(obj.m);
                    $(_this).parents('li').remove();
                } 
            },'json');
        });
    }
	 $('#dphone').blur(function(){
	 	var phone=$(this).val();
	 	if(phone!=""){
	 		var url="{:U('Store/yz')}?phone="+phone
	 		$.get(url,function(obj){
	 		if(obj.s){
	 			$('#dphone').attr('did',obj.d);
	 		}else{
	 			alert("经销商手机号不对！");
	 			$('#dphone').val('');
	 		}
	 	})
	 	}
	 })
	 
	$('#phone').blur(function(){
	 	var phone=$(this).val();
	 	var url="{:U('Store/user')}?phone="+phone
	 	$.get(url,function(obj){
	 		if(!obj.s){
	 			alert("手机号已注册!");
	 			$('#phone').val('');
	 		}
	 	})
	 	
	 })
	 
	$("#btn").click(function(){
            // 省市区
			var pcd = $("#city-picker3").val();
			var $form = $("#post_form");
            var $data = {};
            var $form_data = $form.serializeArray();
            $.each($form_data, function(k, v){
                $data[v['name']] = v['value'];
            })
            $data['pcd'] = pcd;
            
            $(".upviewer").each(function(){
                var upviewer_val = [];
                $(this).find("img").each(function(){
                    upviewer_val.push($(this).attr('src'));
                });
                $data[$(this).attr("name")] = upviewer_val;
            });
            var submit = function(point){
                $data['lat'] = typeof(point['lat']) != 'undefined' ? point['lat'] : 0;
                $data['lng'] = typeof(point['lng']) != 'undefined' ? point['lng'] : 0;
                $.post($form.attr('action'), $data, function(obj){
                    alert(obj.m);
                    if(obj.s){
                        if(typeof(obj.url)!= "undefined" && obj.url){
                            location.href = obj.url;
                        }
                    }
                })
            }
            address = pcd.split("/").join("")+$data['address'];
            if(address){
                // 获取经纬
                getPlace(address, submit);
            }else{
                submit({});
            }
		})
	});
</script>
